package br.com.musclebook.service;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;

import br.com.musclebook.entity.User;

@Stateless
public class UserService {

    @Inject
    private UserDAO dao;

    public User insert(User user) {
	user = dao.insert(user);
	return this.find(user.getId());
    }

    public User update(User user) {
	dao.update(user);
	return this.find(user.getId());
    }

    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public User find(Long id) {
	User user = dao.find(id);
	return user;
    }

    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public User authenticate(String username, String password) {
	return this.dao.authenticate(username, password);
    }

}
